package com.qcxk.yuqian.system.component.uploadFile;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.multipart.MaxUploadSizeExceededException;

import java.util.HashMap;
import java.util.Map;

@RestControllerAdvice
public class FileSizeBeyondLimitExceptionHandler {

    @Value("${spring.servlet.multipart.max-file-size}")
    private String maxFileSize;

    /* spring默认上传大小1MB 超出大小捕获异常MaxUploadSizeExceededException */
    @ExceptionHandler(MaxUploadSizeExceededException.class)
    public Map handleMaxUploadSizeExceededException(MaxUploadSizeExceededException e) {
        HashMap<String, Object> result = new HashMap<>();
        result.put("code", 1);
        result.put("msg", "单个文件大小超出" + maxFileSize + "限制, 请压缩或降低文件质量! ");
        return result;
    }
}
